package com.example.demoratelimit.ratelimit;


import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

@Slf4j
@SpringBootTest
public class DemoProducer {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Test
    public void test() throws InterruptedException {
        String key = "rate_limit_list";
        log.info(" consumer begin ");
        int i = 0;
        int count = 1 * 10000;
        while(true) {
            redisTemplate.opsForList().leftPush(key, i + "");
            if(i > count) {
                break;
            }
            i++;
            if(i % 10000 == 0) {
                TimeUnit.SECONDS.sleep(1);
            }
        }
        Long size = redisTemplate.opsForList().size(key);
        log.info(" consumer end count={}, size={}", count, size);
    }


}
